﻿using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XCI.Windows.Extensions
{
    public static class DateEditExtensions
    {
        public static void Config(this DateEdit edit, string formatString = "yyyy-MM-dd", Action<DateEdit> action = null)
        {
            edit.Properties.DisplayFormat.FormatString = formatString;
            edit.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.EditFormat.FormatString = formatString;
            edit.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.EditMask = formatString;
            action?.Invoke(edit);
        }

        public static void ConfigDate(this TextEdit edit, Action<TextEdit> action = null)
        {
            var formatString = "yyyy-MM-dd";
            edit.Properties.DisplayFormat.FormatString = formatString;
            edit.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.EditFormat.FormatString = formatString;
            edit.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.Mask.EditMask = formatString;
            action?.Invoke(edit);
        }

        public static void ConfigDateTime(this TextEdit edit, Action<TextEdit> action = null)
        {
            var formatString = "yyyy-MM-dd HH:mm:ss";
            edit.Properties.DisplayFormat.FormatString = formatString;
            edit.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.EditFormat.FormatString = formatString;
            edit.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.Mask.EditMask = formatString;

            action?.Invoke(edit);
        }
    }
}